package com.gzhu.knowledgeAdmin.repository;

import com.gzhu.knowledgeAdmin.entity.Category;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 录音员 dao
 * Integer 为主键类型
 */
@Repository(value = "categoryRepository")
public interface CategoryRepository extends JpaRepository<Category,Integer> {

    /**
     * 根据category,获取数据
     * 若category为空,则获取分类(一级菜单)
     * 不为空,则根据分类获取应用场景(二级菜单)
     * @param category
     * @return
     */
    List<Category> getCategoryByCategory(String category);

    /**
     * 根据ids获取对应的category集合
     * @param ids
     * @return
     */
    List<Category> getCategoryByIdIn(List<Integer> ids);

    /**
     * 根据category，删除所有
     * @param categoryList
     */
    @Modifying
    @Transactional
    @Query("delete from Category where category in ?1")
    void deleteCategoryByCategoryIn(List<String> categoryList);
}
